﻿#region Copyright (c) 2000-2008 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{       AgDataGrid                                 }
{                                                                   }
{       Copyright (c) 2000-2008 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2008 Developer Express Inc.

using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using DevExpress.AgDataGrid.Data.Helpers;
using System.Collections.Generic;
using DevExpress.AgDataGrid;
namespace DevExpress.AgDataGrid.Data {
	public class RowEditingEventArgs : EventArgs {
		int rowHandle, listIndex;
		object rowObject;
		public int RowHandle { get { return rowHandle; } }
		public int ListIndex { get { return listIndex; } }
		public object RowObject { get { return rowObject; } }
		public bool Cancel { get; set; }
		public RowEditingEventArgs(int rowHandle, int listIndex, object rowObject) {
			this.rowHandle = rowHandle;
			this.listIndex = listIndex;
			this.rowObject = rowObject;
			this.Cancel = false;
		}
	}
	public class RowEditedEventArgs : EventArgs {
		Dictionary<AgDataGridColumn, object> savedValues;
		int rowHandle, listIndex;
		object rowObject;
		bool isCancel;
		public int RowHandle { get { return rowHandle; } }
		public int ListIndex { get { return listIndex; } }
		public object RowObject { get { return rowObject; } }
		public Dictionary<AgDataGridColumn, object> SavedValues { get { return savedValues; } }
		public bool IsCancel { get { return isCancel; } }
		public RowEditedEventArgs(int rowHandle, int listIndex, object rowObject, Dictionary<AgDataGridColumn, object> savedValues, bool cancel) {
			this.rowHandle = rowHandle;
			this.listIndex = listIndex;
			this.rowObject = rowObject;
			this.savedValues = savedValues;
			this.isCancel = cancel;
		}
	}
	public class RowDeletedEventArgs : EventArgs {
		int listIndex;
		public int ListIndex { get { return listIndex; } }
		public RowDeletedEventArgs(int listIndex) {
			this.listIndex = listIndex;
		}
	}
	public class RowDeletingEventArgs : RowDeletedEventArgs {
		public bool Cancel { get; set; }
		public RowDeletingEventArgs(int listIndex)
			: base(listIndex) {
			Cancel = false;
		}
	}
	public class FocusedRowChangedEventArgs : EventArgs {
		int oldRowHandle, newRowHandle, oldVisibleIndex, newVisibleIndex;
		DataController dataController;
		public FocusedRowChangedEventArgs(DataController dataController, int oldRowHandle, int newRowHandle, int oldVisibleIndex, int newVisibleIndex) {
			this.dataController = dataController;
			this.oldRowHandle = oldRowHandle;
			this.newRowHandle = newRowHandle;
			this.oldVisibleIndex = oldVisibleIndex;
			this.newVisibleIndex = newVisibleIndex;
		}
		public int OldRowHandle { get { return oldRowHandle; } }
		public int NewRowHandle { get { return newRowHandle; } }
		public int OldVisibleIndex { get { return oldVisibleIndex; } }
		public int NewVisibleIndex { get { return newVisibleIndex; } }
		public object OldDataRow { get { return GetDataRow(OldRowHandle); } }
		public object NewDataRow { get { return GetDataRow(NewRowHandle); } }
		public bool IsOldRowValid { get { return IsRowValid(OldRowHandle); } }
		public bool IsNewRowValid { get { return IsRowValid(NewRowHandle); } }
		public bool IsOldRowGrouped { get { return IsRowGrouped(OldRowHandle); } }
		public bool IsNewRowGrouped { get { return IsRowGrouped(NewRowHandle); } }
		protected DataController DataController { get { return dataController; } }
		protected object GetDataRow(int rowHandle) {  return DataController.GetRowValue(rowHandle);  }
		protected bool IsRowValid(int rowHandle) { return DataController.IsValidControllerRowHandle(rowHandle); }
		protected bool IsRowGrouped(int rowHandle) { return IsRowValid(rowHandle) && DataController.IsGroupRowHandle(rowHandle); } 
	}
	public class FocusedRowChangingEventArgs : FocusedRowChangedEventArgs {
		public bool Cancel { get; set; }
		public FocusedRowChangingEventArgs(DataController dataController, int oldRowHandle, int newRowHandle, int oldVisibleIndex, int newVisibleIndex) 
			: base(dataController, oldRowHandle, newRowHandle, oldVisibleIndex, newVisibleIndex) {
			Cancel = false;
		}
	}
	public class CustomSummaryEventArgs : EventArgs {
		CustomSummaryProcess summaryProcess;
		object fieldValue;
		int controllerRow;
		int groupRowHandle, groupLevel;
		object item;
		DataController controller;
		public CustomSummaryEventArgs() : this(0, null, null, 0, CustomSummaryProcess.Calculate, null, 0) { }
		public CustomSummaryEventArgs(DataController controller)
			: this() {
			this.controller = controller;
		}
		public CustomSummaryEventArgs(int controllerRow, object totalValue, object fieldValue, int groupRowHandle, CustomSummaryProcess summaryProcess, object item, int groupLevel) {
			Setup(controllerRow, totalValue, fieldValue, null, summaryProcess, item);
			this.controller = null;
			this.groupRowHandle = groupRowHandle;
			this.groupLevel = groupLevel;
		}
		public object TotalValue { get; set; }
		public bool TotalValueReady { get; set; }
		public int GroupLevel { get { return groupLevel; } }
		public object Item { get { return item; } }
		public CustomSummaryProcess SummaryProcess { get { return summaryProcess; } }
		public int GroupRowHandle { get { return groupRowHandle; } }
		public object FieldValue { get { return fieldValue; } }
		public int RowHandle { get { return controllerRow; } }
		public virtual bool IsGroupSummary { get { return GroupRowHandle < 0; } }
		public virtual bool IsTotalSummary { get { return GroupRowHandle == 0; } }
		protected internal void SetupSummaryProcess(CustomSummaryProcess summaryProcess) {
			this.summaryProcess = summaryProcess;
			TotalValueReady = false;
		}
		protected internal void SetupCell(int controllerRow, object fieldValue) {
			this.controllerRow = controllerRow;
			this.fieldValue = fieldValue;
			TotalValueReady = false;
		}
		protected internal void Setup(int controllerRow, object totalValue, object fieldValue, GroupRowInfo groupRow, CustomSummaryProcess summaryProcess, object item) {
			TotalValueReady = false;
			this.groupRowHandle = 0;
			this.groupLevel = -1;
			this.controllerRow = controllerRow;
			this.fieldValue = fieldValue;
			this.summaryProcess = summaryProcess;
			this.item = item;
			TotalValue = totalValue;
			if(groupRow != null) {
				this.groupRowHandle = groupRow.Handle;
				this.groupLevel = groupRow.Level;
			}
		}
		public object GetValue(string fieldName) {
			if(controller == null) return null;
			return controller.GetRowValue(controllerRow, fieldName);
		}
	}
	public class CustomSummaryExistEventArgs : EventArgs {
		int groupRowHandle, groupLevel;
		object item;
		public CustomSummaryExistEventArgs(int groupRowHandle, int groupLevel, object item) {
			this.item = item;
			this.groupRowHandle = groupRowHandle;
			this.groupLevel = groupLevel;
			Exists = true;
		}
		internal CustomSummaryExistEventArgs(GroupRowInfo groupRow, object item)
			: this(0, -1, item) {
			if(groupRow != null) {
				this.groupRowHandle = groupRow.Handle;
				this.groupLevel = groupRow.Level;
			}
		}
		public object Item { get { return item; } }
		public virtual bool Exists { get; set; }
		public int GroupLevel { get { return groupLevel; } }
		public virtual int GroupRowHandle { get { return groupRowHandle; } }
		public virtual bool IsGroupSummary { get { return GroupRowInfo.IsGroupRowHandle(GroupRowHandle); } }
		public virtual bool IsTotalSummary { get { return !IsGroupSummary; } }
	}
	public class SelectionChangedEventArgs : EventArgs {
		NotifyCollectionChangedAction action;
		int controllerRow;
		static SelectionChangedEventArgs refresh = null, selectAll = null;
		internal static SelectionChangedEventArgs Refresh {
			get {
				if(refresh == null) refresh = new SelectionChangedEventArgs();
				return refresh;
			}
		}
		internal static SelectionChangedEventArgs SelectAll {
			get {
				if(selectAll == null) selectAll = new SelectionChangedEventArgs(NotifyCollectionChangedAction.Add, DataController.InvalidRow);
				return selectAll;
			}
		}
		public SelectionChangedEventArgs() : this(NotifyCollectionChangedAction.Reset, DataController.InvalidRow) { }
		public SelectionChangedEventArgs(NotifyCollectionChangedAction action, int controllerRow) {
			this.action = action;
			this.controllerRow = controllerRow;
		}
		public NotifyCollectionChangedAction Action { get { return action; } }
		public int ControllerRow { get { return controllerRow; } }
	}
	public delegate void CustomSummaryEventHandler(object sender, CustomSummaryEventArgs e);
	public delegate void CustomSummaryExistEventHandler(object sender, CustomSummaryExistEventArgs e);
	public delegate void RowDeletingEventHandler(object sender, RowDeletingEventArgs e);
	public delegate void RowDeletedEventHandler(object sender, RowDeletedEventArgs e);
	public delegate void RowEditingEventHandler(object sender, RowEditingEventArgs e);
	public delegate void RowEditedEventHandler(object sender, RowEditedEventArgs e);
	public delegate void SelectionChangedEventHandler(object sender, SelectionChangedEventArgs e);
	public delegate void FocusedRowChangingEventHandler(object sender, FocusedRowChangingEventArgs e);
	public delegate void FocusedRowChangedEventHandler(object sender, FocusedRowChangedEventArgs e);
}
